package com.wudao.ncmplay.service;

import com.wudao.ncmplay.config.RepeatReadStream;
import com.wudao.ncmplay.pojo.MusicInfo;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.CannotWriteException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.tag.FieldDataInvalidException;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.TagException;

import java.io.File;
import java.io.IOException;

public interface NcmService
{
    /**
     * 获取音乐段中的密码
     * @param stream
     * @return
     */
    byte[] readKey(RepeatReadStream stream) throws IOException;

    /**
     * 读出媒体文件流数据
     * @param stream
     * @return
     * @throws IOException
     */
    String readMetaData(RepeatReadStream stream) throws IOException;

    /**
     * 读取未加密的图片忽然封面信息
     * @param stream
     * @return
     * @throws IOException
     */
    byte[] readAlbumCover(RepeatReadStream stream) throws IOException;

    /**
     * 获取根据获取的音乐源数据流获取音乐流
     * @param stream
     * @param keyByte
     * @return
     */
    byte[] readMusic(RepeatReadStream stream, byte[] keyByte);

    /**
     * 设置音乐文件的格式信息等
     * @param tag
     * @param musicInfo
     * @throws FieldDataInvalidException
     */
    void setMusicTag(Tag tag, MusicInfo musicInfo) throws FieldDataInvalidException;

    /**
     * 转换当前文件
     * @param file
     * @return String 源文件名
     * @throws TagException
     * @throws ReadOnlyFileException
     * @throws CannotReadException
     * @throws InvalidAudioFrameException
     * @throws IOException
     * @throws CannotWriteException
     */
    String ncm2NormalFormat(File file) throws TagException, ReadOnlyFileException, CannotReadException, InvalidAudioFrameException, IOException, CannotWriteException;
}
